import { defineComponent as w, openBlock as o, createElementBlock as i, createElementVNode as e, toDisplayString as p, createCommentVNode as k, renderSlot as x, ref as f, createBlock as j, withCtx as L, Fragment as g, renderList as v, createVNode as M, computed as N, normalizeClass as $ } from "vue";
const P = { class: "card" }, V = { class: "flex-between flex-x-center" }, B = {
  key: 0,
  class: "title"
}, I = {
  key: 2,
  class: "right"
}, J = { class: "content" }, D = /* @__PURE__ */ w({
  __name: "CardWrap",
  props: {
    title: { default: "" },
    moreTitle: { default: "更多" },
    showMore: { type: Boolean, default: !1 }
  },
  emits: ["toMore"],
  setup(n, { emit: s }) {
    const t = s, r = () => {
      t("toMore");
    };
    return (c, _) => (o(), i("div", P, [
      e("div", V, [
        c.title ? (o(), i("div", B, p(c.title), 1)) : k("", !0),
        c.showMore ? (o(), i("div", {
          key: 1,
          class: "more",
          onClick: r
        }, [
          e("span", null, p(c.moreTitle), 1),
          _[0] || (_[0] = e("i", { class: "iconfont icon-arrow-right" }, null, -1))
        ])) : (o(), i("div", I, [
          x(c.$slots, "right", {}, void 0, !0)
        ]))
      ]),
      e("div", J, [
        x(c.$slots, "default", {}, void 0, !0)
      ])
    ]));
  }
}), E = (n, s) => {
  const t = n.__vccOpts || n;
  for (const [r, c] of s)
    t[r] = c;
  return t;
}, W = /* @__PURE__ */ E(D, [["__scopeId", "data-v-8e3ecf59"]]), z = {
  key: 0,
  class: "item"
}, F = ["href", "title"], R = ["src"], q = /* @__PURE__ */ w({
  __name: "AiTool",
  props: {
    item: {}
  },
  setup(n) {
    return (s, t) => s.item ? (o(), i("div", z, [
      e("a", {
        href: s.item.url,
        target: "_blank",
        class: "list-item flex-align",
        title: s.item.title
      }, [
        e("img", {
          src: s.item.icon,
          alt: "icon",
          class: "icon"
        }, null, 8, R),
        e("span", null, p(s.item.title), 1)
      ], 8, F)
    ])) : k("", !0);
  }
}), y = (n) => {
  const s = document.cookie.split(";");
  for (let t = 0; t < s.length; t++) {
    const r = s[t].trim();
    if (r.indexOf(n) === 0)
      return r.substring(n.length + 1, r.length);
  }
  return "";
}, G = { class: "tools flex-align-stretch flex-wrap" }, C = /* @__PURE__ */ w({
  __name: "AiToolsCard",
  props: {
    api: { default: "https://china9.cn/api/app/aiToolRecommend" },
    params: { default: () => ({
      limit: 6
    }) },
    config: { default: () => ({
      headers: {
        token: y("token") || y("access_token")
      }
    }) }
  },
  emits: ["toMore"],
  setup(n, { emit: s }) {
    const t = n, r = s, c = () => {
      r("toMore");
    }, _ = f([]);
    return (async () => {
      try {
        const u = await fetch(t.api, {
          method: "POST",
          headers: t.config.headers,
          body: JSON.stringify(t.params)
        }), m = await u.json();
        u.ok && m.code === 200 && m.data ? _.value = m.data : console.log("请求失败");
      } catch (u) {
        console.log("请求出错", u);
      }
    })(), (u, m) => (o(), j(W, {
      class: "ai-wrap",
      title: "AI工具",
      "show-more": !0,
      onToMore: c
    }, {
      default: L(() => [
        e("div", G, [
          (o(!0), i(g, null, v(_.value, (a) => (o(), i("div", {
            key: a.id,
            class: "item-box"
          }, [
            M(q, { item: a }, null, 8, ["item"])
          ]))), 128))
        ])
      ]),
      _: 1
    }));
  }
});
C.install = function(n) {
  n.component("AiToolsCard", C);
};
const H = { class: "ai-tools-page" }, K = {
  key: 0,
  class: "list-container"
}, Q = { class: "list-content flex-wrap" }, U = ["onClick"], X = { class: "icon-box" }, Y = ["src"], Z = {
  key: 1,
  class: "icon-box-bg"
}, tt = { class: "info" }, et = ["title"], st = { class: "desc" }, ot = { key: 1 }, it = { class: "top-box flex" }, nt = { class: "list-title" }, lt = { class: "list-content flex-wrap" }, at = ["onClick"], ct = { class: "icon-box" }, rt = ["src"], dt = {
  key: 1,
  class: "icon-box-bg"
}, pt = { class: "info" }, ut = ["title"], _t = { class: "desc" }, b = /* @__PURE__ */ w({
  __name: "AiToolsPage",
  props: {
    commonApiSettings: { default: () => ({
      api: "https://www.china9.cn/api/app/aiToolOften"
    }) },
    statisticsApiSettings: { default: () => ({
      api: "https://www.china9.cn/api/app/aiToolClick"
    }) },
    toolsListApiSettings: { default: () => ({
      api: "https://www.china9.cn/api/app/getAItoolData"
    }) }
  },
  setup(n) {
    const s = f(y("token") || y("access_token")), t = n, r = N(() => ({
      common: {
        ...t.commonApiSettings.config,
        headers: {
          "Content-Type": "application/json",
          token: s.value
        }
      },
      statistics: {
        ...t.statisticsApiSettings.config,
        headers: {
          "Content-Type": "application/json",
          token: s.value
        }
      },
      tools: {
        ...t.toolsListApiSettings.config,
        headers: {
          "Content-Type": "application/json",
          token: s.value
        }
      }
    })), c = f([]), _ = async () => {
      if (t.commonApiSettings.api != null)
        try {
          const a = await fetch(t.commonApiSettings.api, {
            method: "POST",
            headers: r.value.common.headers,
            body: JSON.stringify(t.commonApiSettings.params)
          }), l = await a.json();
          a.status === 200 && l.code === 200 && l.data ? c.value = l.data : console.log("请求失败");
        } catch (a) {
          console.log("请求失败", a);
        }
    };
    _();
    const A = async (a) => {
      let l = a.url;
      if (!l.includes("http://") && !l.includes("https://") && (l = "http://" + l), window.open(l, "_blank"), t.statisticsApiSettings.api != null)
        try {
          (await fetch(t.statisticsApiSettings.api, {
            method: "POST",
            headers: r.value.statistics.headers,
            body: JSON.stringify(t.statisticsApiSettings.params)
          })).status === 200 ? _() : console.log("请求失败");
        } catch (d) {
          console.log("请求失败", d);
        }
    }, u = f([]);
    return (async () => {
      if (t.toolsListApiSettings.api != null)
        try {
          const a = await fetch(t.toolsListApiSettings.api, {
            method: "POST",
            headers: r.value.tools.headers,
            body: JSON.stringify(t.toolsListApiSettings.params)
          }), l = await a.json();
          a.status === 200 && l.code === 200 && l.data ? u.value = l.data : console.log("请求失败");
        } catch (a) {
          console.log("请求失败", a);
        }
    })(), (a, l) => (o(), i("div", H, [
      c.value.length ? (o(), i("div", K, [
        l[0] || (l[0] = e("div", { class: "top-box flex" }, [
          e("div", { class: "list-title" }, "常用AI工具")
        ], -1)),
        e("div", Q, [
          (o(!0), i(g, null, v(c.value, (d, T) => (o(), i("div", {
            class: "list-item flex",
            key: T
          }, [
            e("a", {
              class: "flex",
              href: "javascript:;",
              onClick: (h) => A(d)
            }, [
              e("div", X, [
                d.icon ? (o(), i("img", {
                  key: 0,
                  src: d.icon,
                  alt: "v.title"
                }, null, 8, Y)) : (o(), i("div", Z, p(d.title.substring(0, 1)), 1))
              ]),
              e("div", tt, [
                e("div", {
                  class: $(["name ellipsis"]),
                  title: d.title
                }, p(d.title), 9, et),
                e("div", st, p(d.content), 1)
              ])
            ], 8, U)
          ]))), 128))
        ])
      ])) : k("", !0),
      u.value.length ? (o(), i("div", ot, [
        (o(!0), i(g, null, v(u.value, (d, T) => (o(), i("div", {
          key: T,
          class: "list-container"
        }, [
          e("div", it, [
            e("div", nt, p(d.title), 1)
          ]),
          e("div", lt, [
            (o(!0), i(g, null, v(d.list, (h, O) => (o(), i("div", {
              class: "list-item flex",
              key: O
            }, [
              e("a", {
                class: "flex",
                href: "javascript:;",
                onClick: (ft) => A(h)
              }, [
                e("div", ct, [
                  h.icon ? (o(), i("img", {
                    key: 0,
                    src: h.icon,
                    alt: "v.title"
                  }, null, 8, rt)) : (o(), i("div", dt, p(h.title.substring(0, 1)), 1))
                ]),
                e("div", pt, [
                  e("div", {
                    class: $(["name ellipsis"]),
                    title: h.title
                  }, p(h.title), 9, ut),
                  e("div", _t, p(h.content), 1)
                ])
              ], 8, at)
            ]))), 128))
          ])
        ]))), 128))
      ])) : k("", !0)
    ]));
  }
});
b.install = function(n) {
  n.component("AiToolsPage", b);
};
let ht = [C, b];
const mt = (n) => {
  ht.map((s) => {
    n.component(s.__name, s);
  });
};
let S = window;
if (typeof S < "u" && S.Vue) {
  const n = S.Vue.createApp({});
  mt(n);
}
export {
  C as AiToolsCard,
  b as AiToolsPage,
  mt as default
};
